{extend name="../../admin/view/main"}

{block name='content'}
<form action="{:sysuri()}" class="layui-card layui-form" data-auto="true" method="post">
    <div class="layui-card-body">

        <label class="layui-input-inline">
            <select class="layui-select" lay-search name="top_ld">
                <option value="">-- 请选择 --</option>
                {if !empty($vo.top_ld)}
                {foreach $fuwuguan_list as $k=>$v}
                <!-- {if $v.id eq $vo.top_ld} -->
                <option selected value="{$v.id}">{$v.nickname|default="无"}</option>
                <!-- {else} -->
                <option value="{$v.id}">{$v.nickname|default="无"}</option>
                <!-- {/if} -->
                {/foreach}
                {else}
                {foreach $fuwuguan_list as $k=>$v}
                <option value="{$v.id}">{$v.nickname|default="无"} </option>
                {/foreach}
                {/if}
            </select>
        </label>


        <div class="hr-line-dashed"></div>
        {notempty name='vo.id'}<input name='id' type='hidden' value='{$vo.id}'>{/notempty}

        <div class="layui-form-item text-center">
            <button class="layui-btn" type="submit">保存数据</button>
            <button class="layui-btn layui-btn-danger" data-history-back data-confirm="确定要取消编辑吗？" type='button'>取消编辑</button>
        </div>
    </div>

</form>

<script>

    $(function () {
        getQybqList();
    });
    function getQybqList() {
        layui.use('xmSelect', function () {
            $.ajax({
                type: 'get',
                url: "{:url('getQybqList')}",
                data: "",
                dataType: "json",
                success: function (res) {
                    if (res.code) {
                        console.log(res);
                        var datas = [];
                        res.data.forEach(function (item) {
                            var uuid = "{$vo.qybq|default=''}".split(',');
                            if (uuid.length && uuid.findIndex(it => it == item.id) != -1) {
                                datas.push({name: item.name, value: item.id, selected: true});

                            } else {
                                datas.push({name: item.name, value: item.id});
                            }
                        });
                        xmSelect.render({
                            el: '#peipeiList',
                            tips: '请选择企业标签',//选项提示文字
                            filterable: true,//搜索模式
                            data: datas,
                            on: function (data) {
                                var selectArr = data.arr;
                                var seachArr = [];
                                for (var j = 0; j < selectArr.length; j++) {
                                    seachArr.push(selectArr[j].value)
                                }
                                $("#qybq").val(seachArr.toString());
                            }
                        })
                    } else {
                        console.log(res.info);
                    }
                },
                error: function (err) {
                    console.log(err)
                }
            });
        });
    }
</script>
{/block}
